import {makeAutoObservable} from "mobx";
import {CefQueryCfg} from "../message/CefQueryCfg";
import {CefKey} from "../message/CefKey.Const";
import {sendCefQuery} from "../message/cefQueryHandler";
export type ThemeItem = 'light' | 'dark';

class ThemeStore {
    private _currentTheme: ThemeItem;
    constructor() {
        makeAutoObservable(this);
        this._currentTheme = 'dark';
    }

    get currentTheme(): ThemeItem {
        return this._currentTheme;
    }

    set currentTheme(value: ThemeItem) {
        this._currentTheme = value;
    }
}
export const themeInstance = new ThemeStore();

export const initTheme = () => {
    const cfg = new CefQueryCfg(CefKey.EVENT_COMMON_PLATFORM);
    cfg.data = {
        method: 'platform.theme',
        params: {
            method: 'isThemeDark'
        }
    }
    sendCefQuery(cfg, (response)=>{
        themeInstance.currentTheme = JSON.parse(response).body === 'false' ? 'light': 'dark';
    });
}